from sqlalchemy import Column, INTEGER, CLOB
from sqlalchemy.ext.declarative import declarative_base
from sqlalchemy_dm import VARCHAR2,DATE,NUMBER

Base = declarative_base()

class RiskDictionary(Base):
    #模式名
    __table_args__  = {'schema': 'ESUNTEST'}
    #表名
    __tablename__   = 'HX_BI_FXZD'
    # 表结构
    ID = Column(INTEGER, primary_key=True, autoincrement=True)
    GSMC    = Column(VARCHAR2(100))
    FXLX    = Column(VARCHAR2(100))
    RQ  = Column(DATE)
    C1  = Column(VARCHAR2(36))
    C2  = Column(VARCHAR2(128))
    C3  = Column(VARCHAR2(1024))
    C4  = Column(VARCHAR2(1024))
    C5  = Column(VARCHAR2(700))
    C6  = Column(VARCHAR2(400))
    C7  = Column(VARCHAR2(1000))
    C8  = Column(VARCHAR2(256))
    C9  = Column(VARCHAR2(256))
    C10 = Column(VARCHAR2(256))
    C11 = Column(CLOB)
    C12 = Column(VARCHAR2(500))
    FXDL = Column(VARCHAR2(36))
    PCH = Column(VARCHAR2(128))
    ZJB_ID  = Column(NUMBER)
    FBRQ    = Column(VARCHAR2(64))
    FBND    = Column(NUMBER)

    @classmethod
    def from_dict(cls, data):
        return cls(
            ID = int(data.get('ID')) if data.get('ID') is not None else 0,
            GSMC = data.get('GSMC'),
            FXLX = data.get('FXLX'),
            RQ = data.get('RQ'),
            C1 = data.get('C1'),
            C2 = data.get('C2'),
            C3 = data.get('C3'),
            C4 = data.get('C4'),
            C5 = data.get('C5'),
            C6 = data.get('C6'),
            C7 = data.get('C7'),
            C8 = data.get('C8'),
            C9 = data.get('C9'),
            C10 = data.get('C10'),
            C11 = data.get('C11'),
            C12 = data.get('C12'),
            FXDL = data.get('FXDL'),
            PCH = data.get('PCH'),
            ZJB_ID = data.get('ZJB_ID'),
            FBRQ = data.get('FBRQ'),
            FBND = data.get('FBND')
        )

    def to_dict(self):
        return {
            'ID' : self.ID,
            'GSMC' : self.GSMC,
            'FXLX' : self.FXLX,
            'RQ' : self.RQ,
            'C1' : self.C1,
            'C2' : self.C2,
            'C3' : self.C3,
            'C4' : self.C4,
            'C5' : self.C5,
            'C6' : self.C6,
            'C7' : self.C7,
            'C8' : self.C8,
            'C9' : self.C9,
            'C10' : self.C10,
            'C11' : self.C11,
            'C12' : self.C12,
            'FXDL' : self.FXDL,
            'PCH' : self.PCH,
            'ZJB_ID' : self.ZJB_ID,
            'FBRQ' : self.FBRQ,
            'FBND' : self.FBND
        }
